package myJs.tool

import scalatags.Text.all._
import myJs.Utils._
import myJs.myPkg.jquery._
import scalatags.Text.all

/**
 * Created by yz on 28/5/2020
 */
trait BootstrapTableTool {

  def getFilterSelectHtml(field: String) = {
    select(`type` := "text", filterDataField := field, `class` := s"myFilter filterSelect form-control  search-input",
      width := "100%")
  }

  def getFilterSelect2Html(field: String) = {
    input(id := "mySelect2", `type` := "text", `class` := s"myFilter filterSelect2 form-control  search-input",
      filterDataField := field, onclick := "SampleManage.showSelect2(this)", value := "0个分析 选中", readonly,
    )
  }

  def getFilterInputHtml(field: String) = {
    input(`type` := "text", filterDataField := field, `class` := s"myFilter  form-control  search-input",
      value := "")
  }

  def initFilterSearch(fieldNames: List[String]) = {
    fieldNames.foreach { id =>
      $(s"th[data-field='${id}']").append(getFilterSearchHtml(id).render)
    }
  }

  def getFilterSearchHtml(field: String) = {
    span(`class` := "myFilter",
      a(marginLeft := 8, `class` := s"myFilter mySearch",
        onclick := "SampleManage.execFilter", title := "搜索", cursor.pointer,
        filterDataField := "operate",
        span(
          em(cls := "fa fa-search")
        )
      ),
      all.raw("&nbsp;"),
      a(
        title := "清除", filterDataField := "operate", `class` := s"myFilter mySearch",
        cursor.pointer,
        onclick := s"SampleManage.clearFilter",
        span(
          em(cls := "fa fa-trash")
        )
      )
    )
  }

  def getFilterHiddenHtml(field: String) = {
    div(`type` := "hidden", height := 34, filterDataField := field, `class` := s"myFilter filterInput search-input", width := "100%")
  }

  def initFilterSelect(fieldNames: List[String]) = {
    fieldNames.foreach { id =>
      $(s"th[data-field='${id}']").append(getFilterSelectHtml(id).render)
    }
  }

  def initFilterSelect2(fieldNames: List[String]) = {
    fieldNames.foreach { id =>
      $(s"th[data-field='${id}']").append(getFilterSelect2Html(id).render)
    }
  }

  def initFilterInput(fieldNames: List[String]) = {
    fieldNames.foreach { id =>
      $(s"th[data-field='${id}']").append(getFilterInputHtml(id).render)
    }
  }

  def initFilterHidden(fieldNames: List[String]) = {
    fieldNames.foreach { id =>
      $(s"th[data-field='${id}']").append(getFilterHiddenHtml(id).render)
    }
  }




}
